package com.jeecms.wicool.dao.orders.impl;


import java.util.List;

import org.springframework.stereotype.Repository;

import com.jeecms.common.hibernate3.Finder;
import com.jeecms.common.hibernate3.HibernateBaseDao;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.orders.OrderLogDao;
import com.jeecms.wicool.entity.orders.OrderLog;

@Repository
public class OrderLogDaoImpl extends HibernateBaseDao<OrderLog, Integer>
		implements OrderLogDao {

	@Override
	protected Class<OrderLog> getEntityClass() {
		// TODO Auto-generated method stub
		return OrderLog.class;
	}
	@Override
	public Pagination getPage(Integer dingdanId,Short orderStatus,
			int pageNo, int pageSize) {
			Finder f = Finder.create("select bean from OrderLog bean where 1=1 ");
			if(null!=dingdanId){
				f.append(" and bean.dingdan.id = :dingdanId");
				f.setParam("dingdanId",dingdanId);
			}if(null!=orderStatus){
				f.append(" and bean.orderStatus = :orderStatus");
				f.setParam("orderStatus",orderStatus);
			}
			f.append(" order by bean.id desc");
			return find(f, pageNo, pageSize);
	}
	@Override
	public OrderLog findById(Integer id) {
		OrderLog entity = get(id);
		return entity;
	}
	
	@Override
	public List<OrderLog> getAll() {
		Finder f= Finder.create("select bean from OrderLog bean");
		f.append(" order by bean.id desc");
		return find(f);
	}
	@Override
	public List<OrderLog> getByOrderId(Integer orderId) {
		Finder f= Finder.create("select bean from OrderLog bean where bean.order.id="+orderId);
		f.append(" order by bean.id desc");
		return find(f);
	}
	@Override
	public OrderLog save(OrderLog bean) {
	getSession().save(bean);
		return bean;
	}
}